<?php
class loginController extends userController {

	public function index() {
		$this->show();
	}

	public function login() {
		$_POST=in($_POST);
		if(empty($_POST['username'])||empty($_POST['password'])){
            $this->msg('请填写完整登录信息!',0);
        }
        //获取帐号信息
        $info=model('user_list')->user_info($_POST['username']);
        //进行帐号验证
        if(empty($info)){
            $this->msg('登录失败! 您输入的帐号不存在!',0);
        }
        if($info['password']<>md5($_POST['password'])){
            $this->msg('登录失败! 您输入的帐号或密码错误!',0);
        }
        if($info['status']==0){
            $this->msg('登录失败! 您已被禁止登录!',0);
        }

        //更新帐号信息
        
        $data=array();
        $data['uid']=$info['uid'];
        $data['last_time']=time();
        $data['last_ip']=get_client_ip();
        model('user_list')->edit($data);

        //设置登录信息
        $cookie=$info['uid'];
        if($_POST['remember']){
        	$expire = time() + 604800;
        }else{
        	$expire = time() + 7200;
        }
        $this->setLogin($cookie,$expire);
        $this->msg('登录成功');

	}

    public function login_html(){
		$user_info=model('user_list')->info($this->user_id);
        if($this->isLogin()){
            echo '您好 ['.$user_info['username'].']，欢迎您再次回来 ，进入<a href="'.url('member/index/index').'">用户中心</a>管理您的信息，您可以<a href="'.url('information/logout').'">退出登录</a>';
        }else{
            echo '您好，欢迎光临本站 <a href="'.url('member/login/index').'" class="blue">登录</a><a href="'.url('member/register/index').'" class="blue">注册</a> <a href="'.url('member/index/index').'">用户中心</a>';
        }
    }

    public function logout() {
        $this->setLogin('',0);
        $this->redirect(url('index/index'));
    }


}